package com.gopay.checkorder.manager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.checkorder.dao.OrderAdRecordDAO;
import com.gopay.checkorder.manager.OrderAdRecordManager;
import com.gopay.common.constants.order.CheckOrderJoin;
import com.gopay.common.domain.cps.CpsOrderAdjustRecord;

/**
 * 订单调整Manager实现
 * 
 * @OrderAdRecordManagerImpl.java
 * @author yaobo
 * @2013-11-8 上午10:24:29 www.gopay.com.cn Inc.All rights reserved.
 */
@Service("orderAdRecordManager")
public class OrderAdRecordManagerImpl implements OrderAdRecordManager {
    @Resource(name = "orderAdRecordDAO")
    private OrderAdRecordDAO orderAdRecordDao;

    @Override
    public int lock(String gopayOutOrderId) {
        return orderAdRecordDao.lock(gopayOutOrderId);
    }

    @Override
    public CpsOrderAdjustRecord get(String gopayOutOrderId) {
        return orderAdRecordDao.getByGopayOutOrderId(gopayOutOrderId);
    }

    @Override
    public void update(CpsOrderAdjustRecord record, CheckOrderJoin join) {
        if (join.value == CheckOrderJoin.SYSTEM.value) {
            // 系统自动发起对账时，对账次数+1
            record.setAdjustCounts(record.getAdjustCounts() + 1);
        }

        orderAdRecordDao.update(record);
    }

    @Override
    public List<CpsOrderAdjustRecord> getUnCheckList(String adjustResult, int adjustCounts, int pageIndex, int pageSize) {
        return orderAdRecordDao.getUnCheckList(adjustResult, adjustCounts, pageIndex, pageSize);
    }

    @Override
    public int getUnCheckCount(String adjustResult, int adjustCounts) {
        return orderAdRecordDao.getUnCheckCount(adjustResult, adjustCounts);
    }

}
